package net.exoweb.animate.graphics
{
    import flash.display.*;
    import flash.geom.*;

    import net.exoweb.animate.graphics.GShape;
    import net.exoweb.animate.common.Maths;

    public class GRay extends GShape
    {
        private var _toX:Number;
        private var _toY:Number;
        private var _centerColor:uint;

        public function GRay(x:Number, y:Number, centerColor:uint=0xFFFFFF, color:uint=0x0000FF, bm:String="add")
        {
            super(color, bm);
            _toX = x;
            _toY = y;
            _centerColor = centerColor;
        }

        public function set toX(v:Number):void
        {
            _toX = v;
            display();
        }

        public function get toX():Number
        {
            return _toX;
        }

        public function set toY(v:Number):void
        {
            _toY = v;
            display();
        }

        public function get toY():Number
        {
            return _toY;
        }

        public function set centerColor(v:uint):void
        {
            _centerColor = v;
            display();
        }

        public function get centerColor():uint
        {
            return _centerColor;
        }

        override public function display():void
        {
            graphics.clear();
            graphics.lineStyle(1, color);
            var matr:Matrix = new Matrix();
            var r:Number = Math.sqrt(_toX*_toX + _toY*_toY);
            matr.createGradientBox(r, r, 0, -r/2, -r/2);
            graphics.lineGradientStyle(GradientType.RADIAL,
                                       [_centerColor, color],
                                       [1, 0], [0, 255], matr);
            graphics.moveTo(0, 0);
            graphics.lineTo(_toX, _toY);
        }
    }
}
